/**
 * Created by Administrator on 2017/4/6 0006.
 */
window.onload = function () {
    !(function(win, doc){

        function setFontSize() {
            // 获取window 宽度
            // zepto实现 $(window).width()就是这么干的
            var winWidth =  window.innerWidth;
            // doc.documentElement.style.fontSize = (winWidth / 640) * 100 + 'px' ;

            // 2016-01-13 订正
            // 640宽度以上进行限制 需要css进行配合
            var size = (winWidth / 1080) * 150;
            doc.documentElement.style.fontSize = (size < 150 ? size : 150) + 'px' ;
        }

        var evt = 'onorientationchange' in win ? 'orientationchange' : 'resize';

        var timer = null;

        win.addEventListener(evt, function () {
            clearTimeout(timer);

            timer = setTimeout(setFontSize, 300);
        }, false);

        win.addEventListener("pageshow", function(e) {
            if (e.persisted) {
                clearTimeout(timer);

                timer = setTimeout(setFontSize, 300);
            }
        }, false);

        // 初始化
        setFontSize();

    }(window, document));
    var imgs=['img/home_box.png','img/home_bg.png'];
    var index=0;
    setInterval(function(){
        index++;
        if (index>1) {
            index=0
        }
        $(".box_pic>div>img").attr("src",imgs[index]);
    },2000);

    $('.pay-head>span:nth-child(1)').click(function(){
        $('.pay-box').hide()
    });
    $('.buy_project_four>button').click(function(){
        $('.pay-box').show()
    });
    commodityJs();
    function commodityJs() {
        var flag = true;
        $('#collect').on('click',function () {
            var num = $('#collect').find('span').text();
            if(flag){
                num++;
                $(this)
                    .find('img').attr('src','img/hascollected.png')
                    .end()
                    .find('span')
                    .text(num);
                flag = false;
            }else{
                num--;
                $(this)
                    .find('img').attr('src','img/commodity_collect.png')
                    .end()
                    .find('span')
                    .text(num);
                flag = true;
            }
        });
        $('#share').on('click',function () {
            $('.share-box')
                .show()
                .find('.share')
                .animate({"bottom":0},500);
            $('body').css('overflow-y','hidden');
        });
        $('#shareCancle').on('click',function () {
            $('.share-box')
                .find('.share')
                .animate({"bottom":"-3.5rem"},500,function () {
                    $('.share-box').hide();
                });

            $('body').css('overflow-y','visible');
        })
    }
}
